#include "eyebot.h"

#define NO_HUE 255

/* -----------= colours =-------------- */
#define BLACK  0
#define WHITE 15


/**
   Init camera.
 */
void Init_Cam();

/** Change camera parameters.
    Changes brightness, hue and saturation in case default values
    aren't good enough (e.g. different light conditions). Function as
    in RoBiOS-Setup, but without camera-initialisation, works only for
    colour-camera.
 */
void set_cam_parameters();

/** Change parameters.
    Changes thresholds which are used to select ball/goal coloured
    pixels from others and size of ball/goal.
 */
void set_img_parameters();

/** Set whitepoint.
    Set  colour detected in middle of picture
    (mean value of 5x5 area around middle of picture).
    to white by defining multipliers for R, G and B
    to make their adjusted values equal at this point.
*/

/***********************************************************************/
/** Change RBG to HSV -- use hue only.
    Thomas Braunl, UWA 1998.
    
    param r,g,b rgb value of single pixel
    return hue for single RGB value 
*/
/***********************************************************************/

int RGBtoHue(BYTE r, BYTE g, BYTE b);



void set_white_point(colimage img);

void reset_white_point();

/** correct colour using white point determined in set_white_point() **/

void correct_colour(int *r,int *g,int *b);


/** Compute values for the hue lookup table using
 ** values from RGBtuHUE, which compensates for
 ** chosen white point
 **/

void compute_rgb2hueLUT();

/** Set Ball colour.
    Set ball colour to colour detected in middle of picture
    (mean value of 5x5 area around middle of picture).
*/
void set_ball_colour(colimage img);

int get_ball_col();

/** Mark object.
    Convert colour picture into greyscale (for LCD output),
    mark goal position by drawing a vertical and horizontal white
    line through it. Ball and it's size is displayed by black lines.
 */
void mark_object(image greyimg, int x_middle, int y_middle, int object_size);

/** Search for object.
    Search for reagions in rows, with consecutive matching pixels. 
    Hue error must be below thresh at the endpoints, but between them
    max_lowq_seq consecutive pixels are allowed to match less strictly (thresh2)
    or have undefined hue (NO_HUE).
    max_bad_in_seq pixels in this sequence that do not match at all are
    also allowed.
  */

int find_object(int *row_middle, int *col_middle, int *object_size, int *mean_error,
		int colour, colimage img);


/* Get an image of 82x62 size subsampled from the full 176x144 image */
void get_subsampled_colimage(colimage *img);

/* Send colour image to PC over RS232 
   do 
   $ stty -F/dev/ttyS0 38400
   $ cat /dev/ttyS0 >bild.ppm
   on PC before sending
   view with 
   $ gimp bild.ppm &
   (Try modifying the code for higher speed and see if that works)
*/
void sendRGBData(colimage img);

/* Send greyscale image to PC over RS232 
   do 
   $ stty -F/dev/ttyS0 38400
   $ cat /dev/ttyS0 >bild.ppm
   on PC before sending
   view with 
   $ gimp bild.ppm &
*/
void sendGreyData(image img);


